﻿using System;
using BLL;
using DAL;
using Ext.Net;

namespace ERP.Modules.Report
{
    public partial class Liabilities_Payment_Deadline_SUM : System.Web.UI.UserControl
    {
        readonly clsConnect cls = new clsConnect();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                GetData();
                GetCustomer();
            }
        }

        private void GetData()
        {
            cls.CreateNewSqlCommand();
            cls.AddParameter("@keywords", txtSearch.Text);
            StoreLiabilities_Payment_Deadline_SUM.DataSource = cls.GetData("sp_Get_Liabilities_Payment_Deadline_SUM");
            StoreLiabilities_Payment_Deadline_SUM.DataBind();
        }

        protected void GetCustomer()
        {
            var cus = new Customer_BLL();
            StorecbCustomer.DataSource = cus.BindGirdtb_Customer("");
            StorecbCustomer.DataBind();
        }

        private void GetDataFilterWithCustomer()
        {
            cls.CreateNewSqlCommand();
            cls.AddParameter("@Customer_ID", int.Parse(cbCustomer.SelectedItem.Value));
            StoreLiabilities_Payment_Deadline_SUM.DataSource = cls.GetData("sp_Get_Liabilities_Payment_Deadline_SUM_FilterWithCustomer");
            StoreLiabilities_Payment_Deadline_SUM.DataBind();
        }

        protected void StoreLiabilities_Payment_Deadline_SUM_RefreshData(object sender, StoreReadDataEventArgs e)
        {
            GetData();
            cbCustomer.Clear();
        }

        protected void Search_Event(object sender, DirectEventArgs e)
        {
            GetData();
        }

        protected void StorecbCustomer_RefreshData(object sender, StoreReadDataEventArgs e)
        {
            GetCustomer();
        }

        protected void cbCustomer_Change(object sender, DirectEventArgs e)
        {
            GetDataFilterWithCustomer();
        }
    }
}